import httpclient from 'httpclient';
import api from '../../../api/api_kind.js';
export default {
    data() {
        return {
            username: "admin",
            password: "lenovohit@2018",
            loading: false,
            saveLastUser: true,
            department: {
                visible: false,
                data: []
            }
        };
    },
    methods: {
        login() {
            if (this.username === "") {
                ELEMENT.Message.warning({message: "请输入用户名"});
                return;
            } else if (this.password === "") {
                ELEMENT.Message.warning({message: "请输入密码"});
                return;
            }
            let datas = {
                username: this.username,
                password: this.password
            };
            this.loading = true;
            removeAllSessionStorage();
            httpclient.sendPost(api.LOGIN.AUTH_LOGIN, datas).done((res) => {
                if (res.code !== 1) {
                    this.loading = false;
                    ELEMENT.Message.error({message: res.errorMsg});
                } else {
                    this.loading = false;
                    this.$store.commit('setDepartList', res.data.depts);
                    this.department.visible = true;
                    this.department.data = this.$store.getters.departList;
                    let user = {username:this.username,name:res.data.user.name,mobile:res.data.user.mobile,EmployeeNumber:res.data.user.userId,email:res.data.user.email};
                    this.$store.commit("setUser",user);
                    this.$store.commit("setSystemRoute","");
                }
            }).fail((resFail) => {
                this.loading = false;
                ELEMENT.Message.error({message: resFail.errorMsg});
            });

        },
    },
};
